home *** CD-ROM | disk | FTP | other *** search
- \ AlgoLightBox
- \ Robert Dickow (dickow@uidaho.edu)
- \ a 'light box' application for rhythmic dancing light show
- \ synchronized to 'AlgoMusic'
-
- \ JForth Professional 2.0 code:
-
- \ Please note: This code has not been cleaned up. It
- \ still has remnants of junk from development work,
- \ prior versions, etc. Use and abuse at your own risk.
- \ This code is copyright © 1999 Robert Dickow
-
- \ 'Algopics' was the code and development code name
- \ for AlgoLightBox
-
- \ If you have JForth, this still may not compile
- \ as is, since some of the includes are my work
- \ and I probably won't give them away. At most you'd
- \ only have to rewrite/write a few words. Such as
- \ 0$constant I think and make words for a few
- \ Amiga system calls.
-
- \ One BIG WARNING: Due to a bug in Picasso96, you
- \ will find that your system will crash if you run
- \ more than one instance of this program. The
- \ problem is in the patched AreaEnd routine. I've
- \ notified the P96 people, and they just tell me
- \ that that routine isn't used very often...
- \ meaning that they don't plan to fix it anytime
- \ soon. So, be warned.
-
- \ include? DUMP.REGS jdev:debugger
- include? clone cl:topfile
- .need forbid()
- include ju:exec_support
- .then
- include? ALGOMUSICPORTNAME bs:AlgoPics/AlgoMusic.j
- include? 0$constant ju:str_constant
- include? GR.INIT ju:amiga_graph
- include? ?closebox ju:amiga_events
- include? choose ju:random
- include? { ju:locals
- include? gr.area.init ju:polygon
-
- ANEW Task-AlgoMusic
-
- " $VER: AlgoLightBox V1.0 (7.20.99)" 0$constant VersionID$
-
- " AlgoLightBox V1.0" 0$constant AlgoLightBoxName$
-
- variable AlgoPicsSigNum
- variable AlgoPicsMsgPort
- variable AlgoReplyPort
- variable &AlgoMusicMsgPort
- 5 array AlgoSignal
- variable Active
-
- 4000 constant max_dimension
-
- NewWindow MYWINDOW
-
- \ DEBUG{
- : SetWindowTitles() ( Window 0$window 0$screen -- )
- dup -1 = if-not if>abs then
- swap dup -1 = if-not if>abs then swap
- rot >abs -rot
- CALLVOID intuition_lib SetWindowTitles
- ;
- \ }DEBUG
-
- \ variable 1/F-LAST1
- \ variable 1/F-next
- \ variable 1/f-bitmask
- \ variable 1/f-probit
- \ variable 1/f-flipflop
-
- : GR.OPENAlgoWIN ( -- , Open window to test graphics. )
- gr.init ( just to make sure...opens library )
- AlgoLightBoxName$ >abs myWindow ..! nw_title
- 300 myWindow ..! nw_Width
- 200 myWindow ..! nw_Height
- MyWindow gr.opencurw
- 0= abort" AlgoLightBox couldn't open window!"
- ;
-
- variable changebkgnd
-
- FALSE .IF
- : 1/F ( 1/f-last1 -- 1/f-next , generate next 1/f value)
- 1/f-last1 !
- 0 1/f-next !
- 64 1/f-bitmask !
- 78125 1/f-probit !
- BEGIN
- 1/f-last1 @ 1/f-bitmask @ / 1/f-flipflop !
- 1/f-flipflop @ 1 =
- IF
- 1/f-last1 @ 1/f-bitmask @ - 1/f-last1 !
- THEN
- 10000 choose 1000 * 1/f-probit @ < ( yields 0-10000000)
- IF
- 1 1/f-flipflop @ - 1/f-flipflop !
- THEN
- 1/f-next @ 1/f-flipflop @ 1/f-bitmask @ * + 1/f-next !
- 1/f-bitmask @ 2/ 1/f-bitmask !
- 1/f-probit @ 2* 1/f-probit !
- 1/f-bitmask @ 1 <
- UNTIL
- 1/f-next @
- ;
- .THEN
-
- AlgoMusicMsgPort AlgoMusicMsgPort_copy
-
- : Zero.Variables
- AlgoPicsSigNum off
- AlgoPicsMsgPort off
- &AlgoMusicMsgPort off
- Active off
- 0 AlgoSignal 5 cells erase
- ;
-
- AlgoMessage AlgoCommandMsg
-
- \ DEBUG{
-
-
- : Register ( -- )
- Forbid()
- AlgoMusicPortName FindPort() if
- AlgoCommandMsg
- COMMAND_REGISTER over ..! ammsg_Command
- 0 AlgoSignal @ 24 shift
- 1 AlgoSignal @ 16 shift |
- 2 AlgoSignal @ 8 shift |
- 3 AlgoSignal @ |
- over ..! ammsg_Value1
- 4 AlgoSignal @ over ..! ammsg_Value2
- &AlgoMusicMsgPort @ swap PutMsg()
- Active ON
- Then
- Permit()
- \ active @ if
- \ AlgoReplyPort @ WaitPort() drop
- \ then
- ;
-
- : Unregister ( -- )
- AlgoCommandMsg
- COMMAND_UNREGISTER over ..! ammsg_Command
- &AlgoMusicMsgPort @ swap PutMsg()
- \ AlgoReplyPort @ WaitPort() drop ( AlgoMusic doesn't send a reply )
- Active OFF
- ;
-
- : Quit.AlgoPics ( msg$ -- )
- \ don't output to the program or shell window
- GR-CURWINDOW @ if gr.area.term GR.CLOSECURW then
- count type cr
- Active @ if Unregister then
- 5 0 do i
- AlgoSignal @ ?dup if FreeSignal() then \ free signalbits
- loop
- AlgoPicsMsgPort @ ?dup if DeletePort() then \ delete message port
- AlgoReplyPort @ ?dup if DeletePort() then \ delete message port
- ;
-
-
- variable sigbitmask
-
- variable Voicemask0
- variable Voicemask1
- variable Voicemask2
- variable Voicemask3
- variable Quitmask
-
- variable last-box-X
- variable last-box-Y
- variable last-box-YSIZE
- variable last-box-XSIZE
-
- variable backgndcnt
- variable boxrndflg
-
- : boxrndflg@ ( -- n )
- boxrndflg @
- ;
-
- : My.Clear ( -- )
- 2 choose if-not gr.color@ >r 1 >r else 0 >r then
- 256 0 wchoose dup gr.color@ = abs + gr.color!
- gr.window.rect 5 +
- boxrndflg@ choose if
- gr.highlight
- else
- gr.rect
- then
- r> if r> gr.color! then
- ;
-
- variable last-trianglex1
- variable last-triangley1
- variable last-trianglex2
- variable last-triangley2
- variable last-trianglex3
- variable last-triangley3
- variable tri-counter
-
-
- : Display.rectwin ( -- ) \ just clear window
- gr.mode@
- COMPLEMENT gr.mode!
- gr.window.rect gr.rect
- gr.mode!
- ;
-
-
- : Display.Triangle { | x1 y1 x2 y2 x3 y3 WinWidth WinHeight -- }
- gr.mode@
- gr.color@ ( COMPLEMENT gr.mode! )
- last-trianglex1 @ dup 0< if-not
- last-triangley1 @
- last-trianglex2 @ last-triangley2 @
- last-trianglex3 @ last-triangley3 @
- gr.triangle
- else
- drop
- then
- tri-counter @ 24 mod if-not
- GR-CURWINDOW @ dup ..@ wd_Width -> WinWidth ..@ wd_Height -> WinHeight
- WinWidth 10 wchoose max_dimension min dup -> x1 last-trianglex1 ! WinHeight max_dimension min 10 wchoose dup -> y1 last-triangley1 !
- WinWidth 20 wchoose max_dimension min dup -> x2 last-trianglex2 ! WinHeight max_dimension min 40 wchoose dup -> y2 last-triangley2 !
- WinWidth 30 wchoose max_dimension min dup -> x3 last-trianglex3 ! WinHeight max_dimension min 15 wchoose dup -> y3 last-triangley3 !
- else
- last-trianglex1 @ -> x1
- last-triangley1 @ -> y1
- last-trianglex2 @ -> x2
- last-triangley2 @ -> y2
- last-trianglex3 @ -> x3
- last-triangley3 @ -> y3
- then
- 256 1 wchoose gr.color!
- x1 y1 x2 y2 x3 y3 gr.triangle
- gr.color!
- gr.mode!
- 1 tri-counter +!
- ;
-
- Create LocalSongName 256 allot align
-
- : Get.SongName ( -- )
- Forbid()
- &AlgoMusicMsgPort @
- .. AMMP_SONGNAME LocalSongName 256 cmove
- Permit()
- ;
-
- : Display.SongName ( -- )
- Get.SongName
- Gr-CurWindow @ LocalSongName AlgoLightBoxName$ SetWindowTitles()
- ;
-
- variable last-song
-
- DEFER Display1
- DEFER Display2
- DEFER Display3
- DEFER Display4
-
-
-
- \ DEBUG{
- : RndSort.SongRtns { | N1 N2 RTN -- }
- 10 0 do
- 4 choose -> N1
- 4 choose -> N2
- N1
- Case
- 0 of
- What's Display1
- endof
- 1 of
- What's Display2
- endof
- 2 of
- What's Display3
- endof
- 3 of
- What's Display4
- endof
- ENDCASE
- -> RTN \ put rtn away
- N2
- CASE
- 0 of
- What's Display1
- RTN Is Display1
- endof
- 1 of
- What's Display2
- RTN Is Display2
- endof
- 2 of
- What's Display3
- RTN Is Display3
- endof
- 3 of
- What's Display4
- RTN Is Display4
- endof
- ENDCASE
- -> RTN
- N1
- CASE
- 0 of
- RTN Is Display1
- endof
- 1 of
- RTN Is Display2
- endof
- 2 of
- RTN Is Display3
- endof
- 3 of
- RTN Is Display4
- endof
- ENDCASE
- loop
- ;
- \ }DEBUG
-
- : New.song.setup ( -- )
- -1 last-box-x !
- -1 last-trianglex1 !
- 2 choose 2* boxrndflg !
- 24 choose 2* changebkgnd !
- 256 choose gr.color!
- gr.mode@
- JAM1 gr.mode!
- gr.window.rect gr.rect
- gr.mode!
- Display.SongName
- RndSort.SongRtns
- ;
-
-
- variable line-toggle
- variable last-linex
- variable last-liney
-
- : Display.Line { | width height -- }
- GR-CURWINDOW @ dup >r ..@ wd_Width -> width
- r> ..@ wd_Height -> height
- line-toggle @ 32 mod if-not
- width 1 wchoose
- height 1 wchoose
- last-liney ! last-linex !
- then
- gr.color@
- 30 0 do
- last-linex @ last-liney @
- gr.move
- 255 1 wchoose gr.color!
- width 1 wchoose height 1 wchoose gr.draw
- loop
- gr.color!
- 1 line-toggle +!
- ;
-
- : Display.Box { | xpos ypos rndxsize rndysize xoff yoff -- }
- last-box-X @ dup 0< if-not
- backgndcnt @ 1+ changebkgnd @ mod dup backgndcnt ! if-not My.clear then
- last-box-y @ last-box-XSIZE @ last-box-YSIZE @
- boxrndflg@ choose if
- gr.rect
- else
- gr.highlight
- then
- else
- drop
- then
- GR-CURWINDOW @ dup ..@ wd_Width 16 / dup dup -> xoff 10 * swap wchoose
- dup last-box-x ! -> xpos
- ..@ wd_Height 16 / dup dup -> yoff 10 * swap wchoose
- dup last-box-y ! -> ypos
- yoff 9 * 4 wchoose -> rndysize
- xoff 9 * 4 wchoose -> rndxsize
- 255 1 wchoose gr.color!
- xpos dup rndxsize + dup last-box-xsize !
- ypos swap over rndysize + dup last-box-ysize !
- boxrndflg@ if 2 choose else 0 then if
- gr.rect
- else
- 2 choose if
- gr.dehighlight
- else
- gr.highlight
- then
- then
- ;
-
- Variable CloseBoxWasHit
-
- : ?CloseHit ( -- n )
- ?closebox dup if
- CloseBoxWasHit on
- then
- ;
-
-
- : Process.Signals ( -- )
- 1 0 AlgoSignal @ shift dup Voicemask0 !
- 1 1 AlgoSignal @ shift dup Voicemask1 ! |
- 1 2 AlgoSignal @ shift dup Voicemask2 ! |
- 1 3 AlgoSignal @ shift dup Voicemask3 ! |
- 1 4 AlgoSignal @ shift dup Quitmask ! |
- sigbitmask !
- Begin
- sigbitmask @ wait()
- dup Voicemask2 @ and if ( ." v2 ") Display1 else ( ." ") then
- dup Voicemask3 @ and if ( ." v3 ") Display2 else ( ." ") then
- dup Voicemask0 @ and if ( ." v0 ") Display3 else ( ." ") then
- dup Voicemask1 @ and if ( ." v1 ") Display4 else ( ." ") then
- &AlgoMusicMsgPort @ ..@ AMMP_SongNr
- dup last-song @
- = if-not
- \ cr ." New Song"
- ( cr) last-song !
- New.song.setup
- gr.clear
- else
- drop
- then
- ( cr)
- Quitmask @ and ?terminal 0= not or ?closehit or
- until
- ;
-
- : init.AlgoCommand ( -- )
- AlgoCommandMsg
- 0 over ..! ln_Succ
- 0 over ..! ln_Pred
- 0 over ..! ln_Name
- 0 over ..! ln_Pri
- AlgoReplyPort @ >ABS over ..! mn_ReplyPort
- sizeof() AlgoMessage swap ..! mn_Length
- ;
-
- : Init.AlgoPicsMsgPort ( -- )
- 0" AlgoLightBox" 0 CREATEPORT() ?dup if
- dup
- AlgoPicsMsgPort !
- ..@ mp_SigBit AlgoPicsSigNum !
- else
- " Memory Shortage!?" Quit.AlgoPics
- then
- ;
-
- : Init.AlgoReplyPort ( -- )
- 0" AlgoLightBoxRP" 0 CreatePort() ?dup if
- dup AlgoReplyPort !
- PA_SIGNAL swap ..! mp_Flags
- else
- " Ugh! Why couldn't I create my replyport?" Quit.AlgoPics
- then
- ;
-
- : Alloc.AlgoSignals ( -- -1=success | 0=failure )
- 5 0 do
- -1 AllocSignal() dup -1 = if not leave then
- i AlgoSignal !
- loop
- ;
-
-
- : init.algopics ( -- )
- zero.variables
- Init.AlgoPicsMsgPort
- Init.AlgoReplyPort
- Alloc.AlgoSignals
- Init.AlgoCommand
- ;
-
- : Find.AlgoMusic ( -- successflg )
- Forbid()
- AlgoMusicPortName FindPort()
- dup &AlgoMusicMsgPort !
- dup if
- AlgoMusicMsgPort_copy sizeof() AlgoMusicMsgPort cmove
- TRUE
- then
- Permit()
- ;
-
- : OpenSignOnWindow ( -- )
- MyWINDOW NewWINDOW.setup
- MyWindow
- dup
- ..@ nw_Flags WINDOWSIZING xor over ..! nw_Flags
- 90 Over ..! nw_maxwidth
- 200 Over ..! nw_maxheight
- 95 Over ..! nw_Height
- 200 swap ..! nw_Width
-
- MyWINDOW GR.OPENCurW 0= if abort" AlgoLightBox couldn't open window!" then
- Gr-CurWindow @ AlgoLightBoxName$ dup SetWindowTitles()
- GR.BCOLOR@
- GR.COLOR@
-
- 1 dup GR.COLOR!
- GR.BCOLOR!
- GR.CLEAR
- 0 0 200 200 gr.rect
- 2 GR.COLOR!
- 10 10 GR.MOVE
- " AlgoLightBox V1.0" GR.TEXT
- 10 20 GR.MOVE
- " by Bob Dickow" GR.TEXT
- 10 30 GR.MOVE
- " (dickow@uidaho.edu)" GR.TEXT
- 10 40 GR.MOVE
- " July 18, 1999" GR.TEXT
- 10 60 GR.MOVE
- 3 GR.COLOR!
- " Waiting for AlgoMusic" GR.TEXT
-
- GR.COLOR!
- GR.BCOLOR!
- ;
-
-
-
-
-
-
-
- : do.main ( -- )
- last-song off
- register
-
- MyWINDOW NewWINDOW.setup
- 1024 MyWindow ..! nw_maxwidth
- 768 MyWindow ..! nw_maxheight
-
- MyWINDOW GR.OPENALGOWIN
- if
- gr.area.init
- New.song.setup
- Gr-CurWindow @ AlgoLightBoxName$ dup SetWindowTitles()
- tri-counter off
- process.signals
- " Pretty cool, huh?"
- else
- " Window Opening Problem, Dude!"
- then
- Quit.AlgoPics
- ;
-
- : qt ( -- ) \ temporary quit for interactive prog use
- " Ok Bobby! " Quit.AlgoPics
- ;
-
- : Delay() ( n -- ) CALLVOID dos_lib Delay ;
-
- variable SignOnWindowOpen
-
-
- \ Top level routine. Clone RUN\ Save-image Run <prgname>
- : RUN ( -- )
- SignOnWindowOpen off
- GR.INIT
- AlgoMusicPortName FindPort() if-not
- OpenSignOnWindow
- SignOnWindowOpen On
- Then
- 'C Display.Line is Display3
- 'C Display.Triangle is Display4
- 'C Display.Box is Display2
- 'C Display.RectWin is Display1
- \ 36 choose 1/f-last1 !
- CloseBoxWasHit off
- line-toggle off
- 24 2 mod changebkgnd !
- boxrndflg off
- begin
- AlgoMusicPortName FindPort() if
- SignOnWindowOpen @ if
- GR.CloseCurw
- GR.TERM
- SignOnWindowOpen off
- then
- init.algopics
- Find.AlgoMusic if
- gr.init
- do.main
- CloseBoxWasHit on
- gr.term
- else
- " AlgoMusic not running" quit.algopics
- then
- then
- SignOnWindowOPen @ if
- ?CloseHit drop
- then
- CloseBoxWasHit @ dup if-not
- SignOnWindowOpen @ if-not
- 60 Delay()
- then
- then
- until
- SignOnWindowOpen @
- if
- GR.CLOSECURW
- GR.TERM
- then
- ;
- \ }DEBUG
-